<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>发布委托</title>
    <link rel="stylesheet" th:href="@{/layui-v2.6.4/layui/css/layui.css}" type="text/css"/>
    <link rel="stylesheet" th:href="@{/layui-v2.6.4/layui/css/modules/code.css}" type="text/css"/>
    <script th:src="@{/js/jquery-3.5.1.min.js}"></script>
    <script charset="utf-8" th:src="@{/layui-v2.6.4/layui/layui.js}" type="text/javascript"></script>
    <script>
        layui.use('element', function () {
            var element = layui.element;
        });
    </script>
    <style>
        body {
            height: 100%;
            background: linear-gradient(90deg, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB, #C9CACB);
        }
    </style>
</head>
<body>
<div class="layui-container" style="height: 500px;width: 90%">
    <div class="layui-row" style=" width: 100%;height: 100%; ">
        <div class="layui-col-md12" style="text-align: center; margin: auto;font-size: 20px">
            <b>修改悬赏</b>
            <div style="width: 100%;height: 1px
            ;background:#E0E0E0;"></div>
        </div>
        <br><br>
        <div class="layui-col-md9 layui-col-md-offset4">
            <form  id="form" class="layui-form"  method="get" target="_top">
                <input type="hidden" id="hidden" name="hidden" th:value="${Entru.entMoney}">
                <input type="hidden" id="hidden1" name="hidden1" th:value="${Entru.getEntrustId()}">
                <input type="hidden" id="hidden2" name="hidden2" th:value="${Entru.getEntConsignor()}">
                <div class="layui-form-item" >
                    <label class="layui-form-label" >委托类型:</label>
                    <div class="layui-input-inline">
                        <select  lay-filter="aihao" id="sele" name="sele" disabled="disabled" >
                            <option th:value="${Entru.entType}" th:text="${Entru.entType}" ></option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">委托内容: </label>
                    <div class="layui-input-inline">
                        <input th:value="${Entru.getEntData()}"  type="text" id="content" name="content" required lay-verify="required" placeholder="请输入委托内容"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">酬金: </label>
                    <div class="layui-input-inline">
                        <input th:value="${Entru.getEntMoney()}"  type="text" id="money" name="money" required lay-verify="required" placeholder="请输入酬金"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">完成时间: </label>
                    <div class="layui-input-inline">
                        <input  th:value="${#dates.format(Entru.getGmtEnd(), 'yyyy-MM-dd')}" class="layui-input" id="time" name="time" type="date">
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input class="layui-btn layui-btn-primary" type="button" th:onclick="return resigned([[${Usermoney}]])" value="确认修改">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    function getTime() {
        var date = new Date();
        var fullYear = date.getFullYear();
        var month = date.getMonth() + 1;
        var ms = month < 10 ? "-" + "0" + month : "-" + month;
        var day = date.getDate();
        var ds = day < 10 ? "-" + "0" + day : "-" + day;
        var rs = fullYear + ms + ds;
        return rs;
    }


    function resigned(mo) {
        var re = /^[0-9]+[0-9]*[0-9]*$/ ;
        if($("#content").val().length==0){
            layer.msg('请输入委托内容');
            return false;
        }
        if($("#money").val().length==0){
            layer.msg('请输入酬金');
            return false;
        }
        if(!re.test($("#money").val())){
            layer.msg('请输入数字');
            return false;
        }
/*        if($("#hidden1").val()<$("#money").val()){
            layer.msg('余额不足');
            return false;
        }*/
        var num = $("#money").val()-$("#hidden").val();
        var num1 = mo-num;
        if(num1<0){
            layer.msg('余额不足');
            return false;
        }
        if($("#time").val().length==0){
            layer.msg('请选择日期');
            return false;
        }
        var newTime = $("#time").val();
        var nowTime = getTime();
        var oDate1 = new Date(newTime);
        var oDate2 = new Date(nowTime);
        if(oDate1.getTime() <= oDate2.getTime()){
            layer.msg("完成时间不能小于开始时间！");
            return false;
        }
        $.ajax({
            url: "/preRevEn"
            , type: 'get'
            , async: false
            , data: {
                hidden:$("#hidden1").val()
                ,money1:$("#money").val()
                ,money: num1
                ,content:$("#content").val()
                , time: $("#time").val()
            }
            , success: function (mon) {
                $(window.parent.$("#Money").html('账户资产:'+ mon));
                layer.msg('修改成功');
                setTimeout(function () {
                    location.assign("/Issuedbill/"+$("#hidden2").val())
                },1500);
            }
        });
    }

</script>
</body>
</html>